﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Threading;
//using PotatoSoft.ViewModel;
using System.Windows.Threading;
using GalaSoft.MvvmLight.Messaging;
using PotatoSoft.ViewModel.Messages;


namespace PotatoSoft.VisualOctStudio
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        public App()
        {
            Messenger.Default.Register<AppStartMessage>(this, HandleAppStart);
            Messenger.Default.Register<MainWindowRenderedMessage>(this, HandleMainWindowRendered);
        }

        public void HandleAppStart(AppStartMessage message)
        {
            PotatoSoft.VisualOctStudio.MainWindow mw = new PotatoSoft.VisualOctStudio.MainWindow();
            mw.Show();
        }

        public void HandleMainWindowRendered(MainWindowRenderedMessage message)
        {
            MainWindow.Close();
        }

        /*static SplashScreenWindow spw;
        
        private static void OnLoadedLibrary(string logString, int countOfLibraryToLoad)
        {
            if (spw.progressBar1.Maximum == 0)
                spw.progressBar1.Maximum = countOfLibraryToLoad;
            spw.log.Content = "Ładowanie biblioteki "+logString+"...";
            Action empty=delegate(){};
            spw.log.Dispatcher.Invoke(DispatcherPriority.Render, empty);
            Thread.Sleep(100);
            spw.progressBar1.Value = spw.progressBar1.Maximum - (countOfLibraryToLoad - 1);
            if (countOfLibraryToLoad==0)
            {
                spw.Close();
            }
        }*/


        /*private void Application_Startup(object sender, StartupEventArgs e)
        {
            spw = new SplashScreenWindow();
            spw.Show();
            MainWindow mainWindow = new MainWindow();
            this.MainWindow = mainWindow;
            VisualOctStudioViewModel wm = VisualOctStudioViewModel.GetInstance();
            wm.SetOnLoadedLibraries(new VisualOctStudioViewModel.OnLoadedLibraryDelegate(OnLoadedLibrary));
            try
            {
                wm.LoadLibraries();
                mainWindow.Show();
            }
            catch (LoadResourceException ex)
            {
                MessageBox.Show(ex.Message, "Load Library Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                this.Shutdown();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unknow Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                this.Shutdown();
            }
        }*/
    }
}
